/**
 * Created by Administrator on 2022/8/20.
 */
class Animal {
    public String name;
    private int age;

    public void eat() {
        System.out.println(name+"吃饭饭");
    }

    public int setAge(int age) {
        this.age = age;
        return this.age;
    }
}

// 一般继承不要超过三层
class Dog extends Animal {
    public void dogCall() {
        System.out.println(name+"年龄:"+setAge(7));
        System.out.println(name+"汪汪");
    }
}

class Cat extends Animal{
    public void catCall() {
        System.out.println(name+"年龄:"+setAge(6));
        System.out.println(name+"喵喵");
    }
}

/**
 * dog、cat类中并没有定义任何成员变量，name和age属性肯定是从父类Animal中继承下来的
 * dog、cat访问的eat()方法也是从Animal中继承下来的
 */
public class Demo {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.name = "阿黄";
        dog.dogCall();
        dog.eat();

        Cat cat = new Cat();
        cat.name = "mimi";
        cat.catCall();
        cat.eat();
    }
}

